home *** CD-ROM | disk | FTP | other *** search
/ Delphi Developer's Kit 1996 / Delphi Developer's Kit 1996.iso / power / wfc007.000 / src / cnetfile.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-22  |  4.6 KB  |  216 lines

  1. #include <wfc.h>
  2. #pragma hdrstop
  3.  
  4. /*
  5. ** Author: Samuel R. Blackburn
  6. ** CI$: 76300,326
  7. ** Internet: sammy@sed.csc.com
  8. **
  9. ** You can use it any way you like.
  10. */
  11.  
  12. #if defined( _DEBUG )
  13. #undef THIS_FILE
  14. static char BASED_CODE THIS_FILE[] = __FILE__;
  15. #endif
  16.  
  17. /*
  18. ** CNetworkFileInformation stuff
  19. */
  20.  
  21. IMPLEMENT_SERIAL( CNetworkFileInformation, CObject, 1 )
  22.  
  23. CNetworkFileInformation::CNetworkFileInformation()
  24. {
  25.    m_Initialize();
  26. }
  27.  
  28. CNetworkFileInformation::CNetworkFileInformation( FILE_INFO_3 *source )
  29. {
  30.    Copy( source );
  31. }
  32.  
  33. CNetworkFileInformation::~CNetworkFileInformation()
  34. {
  35.    m_Initialize();
  36. }
  37.  
  38. void CNetworkFileInformation::Copy( FILE_INFO_3 *source )
  39. {
  40.    ASSERT( source != NULL );
  41.  
  42.    if ( source == NULL )
  43.    {
  44.       m_Initialize();
  45.       return;
  46.    }
  47.  
  48. #if ! defined( UNICODE )
  49.    ::UNICODE_to_ASCII( (LPCWSTR) source->fi3_pathname, source->fi3_pathname );
  50.    ::UNICODE_to_ASCII( (LPCWSTR) source->fi3_username, source->fi3_username );
  51. #endif
  52.  
  53.    ID            = source->fi3_id;
  54.    Permissions   = source->fi3_permissions;
  55.    NumberOfLocks = source->fi3_num_locks;
  56.    PathName      = source->fi3_pathname;
  57.    UserName      = source->fi3_username;
  58.  
  59. #if ! defined( UNICODE )
  60.    ::ASCII_to_UNICODE( source->fi3_pathname, (LPWSTR) source->fi3_pathname );
  61.    ::ASCII_to_UNICODE( source->fi3_username, (LPWSTR) source->fi3_username );
  62. #endif
  63. }
  64.  
  65. void CNetworkFileInformation::Empty( void )
  66. {
  67.    m_Initialize();
  68. }
  69.  
  70. void CNetworkFileInformation::m_Initialize( void )
  71. {
  72.    UserName.Empty();
  73.    PathName.Empty();
  74.    ID            = 0;
  75.    Permissions   = 0;
  76.    NumberOfLocks = 0;
  77. }
  78.  
  79. void CNetworkFileInformation::Serialize( CArchive& archive )
  80. {
  81.    CObject::Serialize( archive );
  82.  
  83.    if ( archive.IsStoring() )
  84.    {
  85.       archive << UserName;
  86.       archive << PathName;
  87.       archive << ID;
  88.       archive << Permissions;
  89.       archive << NumberOfLocks;
  90.    }
  91.    else
  92.    {
  93.       archive >> UserName;
  94.       archive >> PathName;
  95.       archive >> ID;
  96.       archive >> Permissions;
  97.       archive >> NumberOfLocks;
  98.    }
  99. }
  100.  
  101. /*
  102. ** CNetworkFiles Stuff
  103. */
  104.  
  105. IMPLEMENT_SERIAL( CNetworkFiles, CNetwork, 1 )
  106.  
  107. CNetworkFiles::CNetworkFiles()
  108. {
  109.    m_Initialize();
  110. }
  111.  
  112. CNetworkFiles::CNetworkFiles( LPCTSTR machine_name )
  113. {
  114.    m_Initialize();
  115.    Open( machine_name );
  116. }
  117.  
  118. CNetworkFiles::~CNetworkFiles()
  119. {
  120.    Close();
  121.    m_Initialize();
  122. }
  123.  
  124. void CNetworkFiles::Close( void )
  125. {
  126.    CNetwork::Close();
  127.  
  128.    if ( m_103InformationBuffer != NULL )
  129.    {
  130.       ::NetApiBufferFree( m_103InformationBuffer );
  131.       m_103InformationBuffer = NULL;
  132.    }
  133. }
  134.  
  135. BOOL CNetworkFiles::Close( CNetworkFileInformation& information )
  136. {
  137.    m_ErrorCode = ::NetFileClose( (LPTSTR) m_WideMachineName, information.ID );
  138.  
  139.    if ( m_ErrorCode == NERR_Success )
  140.    {
  141.       return( TRUE );
  142.    }
  143.    else
  144.    {
  145.       return( FALSE );
  146.    }
  147. }
  148.  
  149. void CNetworkFiles::m_Initialize( void )
  150. {
  151.    m_ErrorCode               = 0;
  152.    m_103InformationBuffer    = NULL;
  153.    m_103ResumeHandle         = 0;
  154.    m_103CurrentEntryNumber   = 0;
  155.    m_103NumberOfEntriesRead  = 0;
  156.    m_103TotalNumberOfEntries = 0;
  157. }
  158.  
  159. BOOL CNetworkFiles::Enumerate( void )
  160. {
  161.    if ( m_103InformationBuffer != NULL )
  162.    {
  163.       ::NetApiBufferFree( m_103InformationBuffer );
  164.       m_103InformationBuffer = NULL;
  165.    }
  166.  
  167.    m_103CurrentEntryNumber   = 0;
  168.    m_103NumberOfEntriesRead  = 0;
  169.    m_103ResumeHandle         = 0;
  170.    m_103TotalNumberOfEntries = 0;
  171.  
  172.    m_ErrorCode = ::NetFileEnum( (LPTSTR) m_WideMachineName,
  173.                                          NULL, 
  174.                                          NULL, 
  175.                                          3, 
  176.                              (LPBYTE *) &m_103InformationBuffer,
  177.                                          65535,
  178.                                         &m_103NumberOfEntriesRead,
  179.                                         &m_103TotalNumberOfEntries,
  180.                                         &m_103ResumeHandle );
  181.  
  182.    if ( m_ErrorCode != NERR_Success || m_103InformationBuffer == NULL )
  183.    {
  184.       return( FALSE );
  185.    }
  186.  
  187.    return( TRUE );
  188. }
  189.  
  190. BOOL CNetworkFiles::GetNext( CNetworkFileInformation& information )
  191. {
  192.    if ( m_103CurrentEntryNumber < m_103TotalNumberOfEntries )
  193.    {
  194.       information.Copy( &m_103InformationBuffer[ m_103CurrentEntryNumber ] );
  195.       m_103CurrentEntryNumber++;
  196.       return( TRUE );
  197.    }
  198.  
  199.    information.Empty();
  200.    return( FALSE );
  201. }
  202.  
  203. void CNetworkFiles::Serialize( CArchive& archive )
  204. {
  205.    CNetwork::Serialize( archive );
  206.  
  207.    if ( archive.IsStoring() )
  208.    {
  209.       archive << m_ErrorCode;
  210.    }
  211.    else
  212.    {
  213.       archive >> m_ErrorCode;
  214.    }
  215. }
  216.